package demoMod.stsconsole.powers;

import demoMod.stsconsole.characters.AbstractPlayer;
import demoMod.stsconsole.core.AbstractCreature;
import demoMod.stsconsole.interfaces.TurnStartLoseBlockSubscriber;
import demoMod.stsconsole.interfaces.TurnStartSubscriber;

public class BlurPower extends AbstractPower implements TurnStartLoseBlockSubscriber, TurnStartSubscriber {
    public static final String ID = "BlurPower";

    public BlurPower(AbstractCreature owner, int amount) {
        super(ID, owner, amount);
    }

    @Override
    public int atTurnStartLoseBlock(AbstractCreature target) {
        return target == this.owner ? 0 : target.getCurrentBlock();
    }

    @Override
    public void atTurnStart(boolean isPlayer) {
        if (this.owner instanceof AbstractPlayer) {
            if (isPlayer) {
                this.amount[0]--;
            }
        } else {
            if (!isPlayer) {
                this.amount[0]--;
            }
        }
        if (this.amount[0] <= 0) {
            this.onRemove();
        }
    }

    @Override
    public String getUpdatedDescriptions() {
        return String.format(this.description, this.amount[0]);
    }
}
